var utils = require("../../utils/utils");
var swipeUp = require("./swipeUp");
var swipeDown = require("./swipeDown");
function readArticle(span, maxUp) {
  var maxUp = maxUp || 5;
  var swipeTimes = 0;
  var startTime = Date.now();
  var count = 0;
  while (true) {
    count = count + 1;
    var randomNumber = utils.getRandom(0, 100);
    if (swipeTimes < maxUp) {
      if (count % 5 == 0) {
        console.log("向上滑动一次");
      }
      swipeUp();
    } else {
      if (randomNumber > 90) {
        if (count % 5 == 0) {
          console.log("向下滑动一次");
        }
        swipeDown();
      } else {
        if (count % 5 == 0) {
          console.log("向上滑动一次");
        }
        swipeUp();
      }
    }
    var watchContentSpan = utils.getRandom(1.5, 3, 1000);
    sleep(watchContentSpan);
    swipeTimes = swipeTimes + 1;
    var endTime = Date.now();
    if (count % 5 == 0) {
      console.log("已看内容-" + (endTime - startTime) / 1000 + "-s");
    }
    if (endTime - startTime >= span * 1000) {
      break;
    }
  }
}

module.exports = readArticle;
